<template>
	<view class="content">
		<image mode="widthFix" style="width: 100%;" :src="imageUrl+'/job_hunting/home/dunhuangbg.jpg'" class="bg-img">
		</image>
		<view style="padding:30rpx;">
			<view class="block menu-block">
				<view @click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职')" class="menu-item">
					<image :src="imageUrl+'/job_hunting/home/full_time_icon.png'" class="menu-icon" mode="widthFix">
					</image>
				</view>
				<view @click="navigate('/page_other/job_hunting/job_list/index?type=2&name=找兼职')" class="menu-item">
					<image :src="imageUrl+'/job_hunting/home/part_time_icon.png'" class="menu-icon" mode="widthFix">
					</image>
				</view>
				<view @click="navigate('/page_other/job_hunting/job_fair/index')" class="menu-item">
					<image :src="imageUrl+'/job_hunting/home/job_fair_icon.png'" class="menu-icon" mode="widthFix">
					</image>
				</view>
			</view>
			<view class="block" style="margin-bottom:15rpx;">
				<view @click="navigate1('/page_other/resume/index')" v-if="identity==1" class="edit-resume">
					<image class="resume-builder" :src="imageUrl+'/job_hunting/home/crtResume.jpg'"></image>
				</view>
				<view @click="navigate('/page_other/position/release_position')" v-if="identity==2" class="edit-resume">
					<image class="resume-builder" :src="imageUrl+'/job_hunting/home/position_builder.jpg'"></image>
				</view>
			</view>
			<view class="menu" v-if="identity==1">
				<view class="menu-block">
					<view @click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职')" class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/1.png'" class="menu-icon"></image>
						<view class="menu-name">全部</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4198&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/2.png'" class="menu-icon"></image>
						<view class="menu-name">普工</view>
					</view>
					<view
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4084&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/3.png'" class="menu-icon"></image>
						<view class="menu-name">销售</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4397')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/4.png'" class="menu-icon"></image>
						<view class="menu-name">服务员</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4966&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/5.png'" class="menu-icon"></image>
						<view class="menu-name">技术员</view>
					</view>
					<view
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4353&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/6.png'" class="menu-icon"></image>
						<view class="menu-name">保洁</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4348')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/7.png'" class="menu-icon"></image>
						<view class="menu-name">保安</view>
					</view>
					<view
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4767&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/8.png'" class="menu-icon"></image>
						<view class="menu-name">司机</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4593&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/9.png'" class="menu-icon"></image>
						<view class="menu-name">建筑工</view>
					</view>
					<view hover-class="none"
						@click="navigate('/page_other/job_hunting/job_list/index?type=1&name=找全职&jobType=4401&jobLevel=2')"
						class="menu-item">
						<image :src="imageUrl+'/job_hunting/index/10.png'" class="menu-icon"></image>
						<view class="menu-name">厨师</view>
					</view>
				</view>
			</view>
			<!-- 求职者筛选 -->
			<view class="block tab-block">
				<view class="tab-item active">最新</view>
			</view>

			<!-- 求职者 -->
			<!-- 最新 -->
			<view class="block list-block">
				<template v-if="list.length>0">
					<template v-if="identity==1">
						<PositionItem :key="item.id" :data="item" v-for="(item) in list"></PositionItem>
					</template>
					<template v-if="identity==2">
						<view @click="goView(item.id)" class="list-item person-item" v-for="(item,index) in list"
							:key="item.id">
							<view class="info-block">
								<image :src="item.user.faceUrl?item.user.faceUrl:imageUrl+'/job_hunting/home/Mr.png'"
									class="user-photo"></image>
								<view class="info">
									<view class="name">{{item.realName}}</view>
									<view class="others" style="display: flex;flex-direction: row;">
										<view class="other-item">{{item.birthday}}岁/</view>
										<view class="other-item" v-if="item.education"> {{item.education}} /
										</view>
										<view class="other-item" v-else> {{item.educationText}} /</view>
										<view class="other-item" v-if="item.workTimeStart=='0年'">
											经验小于1年 /
										</view>
										<view class="other-item" v-else>{{item.workTimeStart}}经验 / </view>
										<view class="other-item"> {{item.jobText}}</view>
									</view>
								</view>
							</view>
							<view class="job-block">
								<view class="job">
									<!-- <view class="label-block">
										<view v-for="(item1,index1) in item.label" class="label-item">{{item1}}</view>
									</view> -->
									<view class="job-content">
										<view class="jobList">
											<text class="darkgray" style="margin-right:10rpx;">想找</text>
											{{item.regArea}} / {{item.postName}} /
											{{item.salaryMin}}-{{item.salaryMax}}元
										</view>
									</view>
								</view>
								<!-- <view class="btn-block">
									<view class="btn">沟通</view>
								</view> -->
							</view>
						</view>
					</template>
				</template>
				<view v-if="list.length==total&&!more" style="text-align: center;">没有更多了哦</view>
				<view v-else style="text-align: center;">暂无数据</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getCustomerListApi,
		getPublishApi
	} from '@/api/job_hunting.js';
	import {
		getStorage
	} from '@/util/auth.js';
	import {
		isMore
	} from '@/util/util.js'
	import {
		getUser
	} from '@/api/user.js'
	import util from '@/util/util.js';
	import {
		mapGetters
	} from 'vuex';
	import PositionItem from "@/page_other/job_hunting/recruit_list/index.vue";
	export default {
		components: {
			PositionItem
		},
		data() {
			return {
				imageUrl: '',

				//求职者
				list: [],
				page: 1,
				limit: 10,
				more: true,
				total: 0,
			}
		},
		methods: {
			navigate1(url) {
				if (this.user) {
					uni.navigateTo({
						url
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '需要先登录！',
						cancelText: '先逛逛',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/page_other/login/select'
								})
							} else {
								// uni.navigateBack();
							}
						}
					})
				}
			},
			navigate(url) {

				if (this.user) {
					if (url == '/page_other/position/release_position') {
						getUser({
							type: 2
						}).then((res) => {
							console.log(res)
							const com = res
							const user = this.$store.getters.user;
							if (com.authenticationStatus == 3) {
								this.showToast('等待审核中，暂不可操作', () => {
									this.$store.dispatch('user/getUser')
									return;
								});

							} else if (com.authenticationStatus == 4) {
								this.showToast('审核不通过，请重新上传', () => {
									this.$store.dispatch('user/getUser')
									return;
								});

							} else if (com.comStatus == 2) {
								this.showToast('请先完善企业信息后发布', () => {
									this.$store.dispatch('user/getUser')
									uni.navigateTo({
										url: '/page_other/company/form'
									})
									return;
								});
							} else {
								this.$store.dispatch('user/getUser')
								uni.navigateTo({
									url
								})
							}
						})
					} else {
						uni.navigateTo({
							url
						})
					}
				} else {
					uni.navigateTo({
						url
					})
				}

			},
			refresh() {
				this.page = 1
				this.more = true
				this.getList(true);
			},
			goView(id) {
				uni.navigateTo({
					url: '/page_other/resume/index?type=view&id=' + id
				})
			},
			async getList(refresh = false) {
				var latitude = uni.getStorageSync('latitude');
				var longitude = uni.getStorageSync('longitude');
				if (this.more) {
					let config = {
						page: this.page,
						limit: this.limit,
						orderDate: 1,
						longitude: longitude,
						latitude: latitude,

					}
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					let res = this.$store.getters.identity == 1 ? await getPublishApi(config) :
						await getCustomerListApi(config);
					let list = res.list ?? [];
					this.list = refresh ? list : [...this.list, ...list],
						this.total = res.count
					this.more = isMore(this.page, this.limit, this.total)
				}
			}
		},

		computed: {
			identity() {
				return this.$store.getters.identity
			},
			...mapGetters(['identity', 'user'])
		},
		onLoad() {
			this.imageUrl = this.globalConfig.imageUrl;
			this.getList(true);
		},
		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
	}
</script>

<style lang="scss">
	$box-shadow: 0 0 10px 0 #efefef;

	page {
		background: #FEFEFE;
	}

	.content {
		width: 100%;

		.menu {
			.menu-block {
				padding: 10rpx 0 10rpx 0;
				width: 100%;
				margin: 0 auto;
				display: flex;
				flex-direction: row;
				position: relative;
				background: #fff;
				border-radius: 5px;
				flex-wrap: wrap;
				box-shadow: 0 0 10px 0 #efefef;
			}

			width: 100%;
			background: #fff;
			border-radius: 20rpx;

			.menu-item {
				width: 20%;
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 26rpx;
				padding: 20rpx 0 20rpx 0;

				.menu-icon {
					margin-top: 10rpx;
					width: 80rpx;
					height: 80rpx;
				}

				.menu-name {
					margin-top: 10rpx;
				}
			}
		}

		.loadingicon {
			width: 100%;
			height: 80rpx;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: center;
		}

		.loading {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			align-items: center;
			justify-content: center;
			position: relative;
			text-align: center;
		}

		.loading .line {
			position: absolute;
			width: 450rpx;
			left: 150rpx;
			top: 50rpx;
			height: 1px;
			border-top: 1px solid #eee;
		}

		.loading .text {
			position: relative;
			display: inline-block;
			padding: 0 20rpx;
			background: #fff;
			z-index: 2;
			color: #777;
		}

		.loadingicon .loading {
			animation: load linear 1s infinite;
			font-size: 45rpx;
			color: #000;
		}

		.loadingicon {
			width: 100%;
			height: 80rpx;
		}

		.bg-img {
			width: 100%;
			position: absolute;
			top: 0;
		}

		.block {
			width: 100%;
			margin-bottom: 40rpx;
			//box-shadow: $box-shadow;
			position: relative;

			.search {
				width: 100%;
				height: 70rpx;
				padding: 0 20rpx;
				font-size: 28rpx;
				//background: #F3F3F3;
				border-radius: 50rpx;
				border: 1px solid #F4F5F7;

				.inputPlaceholder {
					color: #F4F5F7;
				}
			}

			.iconfont.icon-sousuo {
				position: absolute;
				transform: translate(0, -50%);
				right: 20rpx;
				top: 50%;
				font-size: 38rpx;
				font-weight: bold;
				color: #F4F5F7;
			}

			.resume-builder {
				width: 100%;
				height: 260rpx;
				border-radius: 20rpx;
			}

			.enterprise-item {
				display: flex;
				flex-direction: row;

				.photo {
					width: 160rpx;
					height: 160rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
					flex-grow: 0;
				}

				.info {
					position: relative;
					flex-grow: 1;

					.other,
					.jobs {
						margin-top: 20rpx;
					}

					.num {
						color: #FE7526;
					}

					.postion {
						position: absolute;
						bottom: 12rpx;
						right: 0;

						.iconfont {
							margin-right: 10rpx;
						}
					}
				}
			}
		}

		.block.swiper-block {
			height: 300rpx;
			border-radius: 20rpx;
			box-shadow: none;
		}

		.block.menu-block {
			margin-top: 350rpx;
			border-radius: 20rpx;
			//background: #fff;
			//height: 200rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;

			.menu-item {
				width: calc(100%/3 - 20rpx);
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 30rpx;
				//justify-content: center;

				.menu-icon {
					width: 100%;
					//width: 100rpx;
					//height: 100rpx;
				}

				.menu-name {
					font-size: 28rpx;
					margin-top: 20rpx;
				}
			}

			.menu-item:nth-child(3n) {
				margin-right: 0;
			}
		}

		.block.tab-block {
			box-shadow: none;
			display: flex;
			flex-direction: row;
			justify-content: left;
			flex-wrap: wrap;
			margin-bottom: 20rpx;

			.tab-item {
				padding: 10rpx 15rpx;
				font-weight: bold;
				font-size: 30rpx;
				margin-right: 30rpx;
			}

			.tab-item.active {
				background: url("https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/home/tab_selected_bg.png") no-repeat right bottom;
				background-size: 70%;
				font-size: 32rpx;
			}
		}

		.block.list-block {
			box-shadow: none;
			display: flex;
			flex-direction: column;
			margin-bottom: 0;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				box-shadow: $box-shadow;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				margin-bottom: 20rpx;

				.detail-info {
					width: 260rpx;
					// height: 200rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;

					.name {
						width: 110rpx;
						font-size: 24rpx;
						color: #999;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						text-align: center;
						text-indent: 15rpx;
					}

					.photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.apply-btn {
						border: 1px solid #FE7526;
						border-radius: 8rpx;
						color: #FE7526;
						font-size: 24rpx;
						padding: 8rpx 28rpx;
						position: relative;
						left: 30rpx;
					}
				}

				.list-info {
					// width: calc(100% - 180rpx);
					width: 100%;
					display: flex;
					flex-direction: column;

					>view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.title-info {
						display: flex;
						flex-direction: row;
						align-items: center;

						.title {
							color: #000;
							font-weight: bold;
							font-size: 34rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.fast-job {
							width: 60rpx;
							height: 38rpx;
							border: 1rpx solid #FE7526;
							font-size: 24rpx;
							text-align: center;
							color: #FE7526;
							margin-left: 20rpx;
							border-radius: 6rpx;
						}
					}

					.detail-item {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.money-item {
							margin-top: 20rpx;

							.wage {
								color: #FE7526;
								font-size: 36rpx;
								font-weight: bold;

								.unit {
									font-size: 28rpx;
									font-weight: normal;
								}
							}
						}

						.detail-info {
							width: 180rpx;
							// height: 200rpx;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							justify-content: center;
							align-items: center;

							.name {
								width: 110rpx;
								font-size: 24rpx;
								color: #999;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								text-align: center;
								text-indent: 15rpx;
							}

							.photo {
								width: 70rpx;
								height: 70rpx;
								border-radius: 100%;
								background: #efefef;
							}

							.apply-btn {
								border: 1px solid #FE7526;
								border-radius: 8rpx;
								color: #FE7526;
								font-size: 24rpx;
								padding: 8rpx 28rpx;
								position: relative;
								left: 30rpx;
							}
						}
					}

					.address-item {
						display: flex;
						justify-content: space-between;

						.address {
							width: 440rpx;
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.distance {
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
						}
					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}
				}
			}

			.person-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding: 0 30rpx;
				margin-bottom: 30rpx;

				.info-block,
				.job-block {
					width: 100%;
					padding: 20rpx 0;
				}

				.info-block {
					border-bottom: 1px solid #efefef;
					display: flex;
					flex-direction: row;
					align-items: center;

					.user-photo {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}

					.info {
						width: calc(100% - 120rpx);
						margin-left: 20rpx;

						.name {
							font-weight: bold;
							font-size: 34rpx;
						}

						.others {
							display: flex;
							flex-direction: row;

							.other-item {
								font-size: 26rpx;
								color: #999;
								margin-top: 14rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}

					}
				}

				.job-block {
					display: flex;
					flex-direction: row;
					align-items: center;

					.job {
						width: 100%;
						display: flex;
						flex-direction: column;
						justify-content: center;

						.label-block {
							width: 100%;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;

							.label-item {
								background: #F4F5F7;
								color: #999;
								font-size: 24rpx;
								padding: 4rpx 10rpx;
								margin-right: 20rpx;
								margin-bottom: 20rpx;
							}
						}

						.job-content {
							width: 100%;
							font-size: 26rpx;

							.jobList {
								width: 100%;
							}
						}
					}

					.btn-block {
						width: 140rpx;
						display: flex;
						align-items: center;
						justify-content: center;

						.btn {
							padding: 6rpx 26rpx;
							border: 1px solid #FE7526;
							border-radius: 6rpx;
							color: #FE7526;
							font-size: 24rpx;
						}
					}
				}
			}

			.person-item:last-child {
				margin-bottom: 0;
			}
		}
	}
</style>